<script setup lang="tsx">
import {
  partDeliveryApplyListApi,
  partDeliveryApplyAuditApi,
  checkExceptionOrderItem,
  noDeliveryApi
} from '@/api/order'
import DialogShopChecked from '../../../components/DialogShopChecked/index.vue'
import { useEnumeratePicker } from '@/utils'
import { ElMessageBox, ElMessage } from 'element-plus'
const { t } = useI18n()
const { push, go } = useRouter()
const isExpanded = ref(true)
const togglePanel = () => {
  isExpanded.value = !isExpanded.value
}

const emit = defineEmits(['refresh'])
// 使用具体类型定义 props
const props = defineProps({
  currentRow: {
    type: Object,
    default: () => null
  },
  operatorOptions: {
    type: Object,
    default: () => null
  }
})

// 定义 dataList 变量
const dataList = ref<any[]>([])
if (props.currentRow.isWholesal) {
  dataList.value = props.currentRow.products_list || []
} else {
  dataList.value = props.currentRow.list || []
}

// 移动端检测
import { useAppStore } from '@/store/modules/app'
const appStore = useAppStore()
const isMobile = computed(() => appStore.getMobile)
const partDeliveryList = ref<any[]>([])
const originalPartDeliveryList = ref<any[]>([])
const getPartDeliveryList = async () => {
  const res = await partDeliveryApplyListApi({
    order_id: props.currentRow.id
  })
  originalPartDeliveryList.value = res.data
  partDeliveryList.value = res.data.reduce((acc, cur) => {
    if (Array.isArray(cur.items)) {
      // Add outer id and status to each item
      const itemsWithExtra = cur.items.map((item) => ({
        ...item,
        id: cur.id,
        status: cur.status,
        create_time: cur.create_time
      }))
      return acc.concat(itemsWithExtra)
    }
    return acc
  }, [])
}
const handleAudit = (row: Record<string, any>) => {
  // 二次确认弹窗
  ElMessageBox.confirm(t('common.message.review'), t('common.tip'), {
    confirmButtonText: t('common.ok'),
    cancelButtonText: t('common.cancel'),
    type: 'warning'
  })
    .then(async () => {
      // 审核接口调用
      try {
        let partDeliveryAmount = 0
        originalPartDeliveryList.value.map((el) => {
          if (el.id === row.id) {
            partDeliveryAmount = el.items.reduce((sum, item) => {
              return sum + Number(item.actual_selling_price) * Number(item.apply_quantity)
            }, 0)
          }
        })
        const res = await partDeliveryApplyAuditApi({
          id: row.id,
          part_delivery_amount: partDeliveryAmount
        })
        console.log('部分发货申请审核res', res)
        if (res.code === 0) {
          ElMessage.success('审核成功')
          // getPartDeliveryList()
          emit('refresh')
        }
      } catch (e) {
        // 失败处理
      }
    })
    .catch(() => {
      // 取消操作
    })
}
const handleJump = (row: Record<string, any>) => {
  const path = ref<string>('') // 默认值为空字符串
  const query = reactive<{ [key: string]: string }>({}) // 默认值为空字符串
  path.value = `/order/order-management/delivery`
  query.id = props.currentRow.id
  query.is_part_delivery = 'true'
  push({ path: path.value, query })
}
onMounted(() => {
  getPartDeliveryList()
})
defineExpose({
  getPartDeliveryList
})

// 合并

// 合并单元格的方法
// 合并“操作”列：id相同的行合并到一起
const mergeCells = ({ row, column, rowIndex }) => {
  if (column.label === '操作') {
    // 获取当前表格数据
    const tableData = partDeliveryList.value || []
    // 当前行的id
    const currentId = row.id
    // 找到第一个出现该id的行索引
    const firstIndex = tableData.findIndex((item) => item.id === currentId)
    // 统计该id出现的次数
    const count = tableData.filter((item) => item.id === currentId).length
    if (rowIndex === firstIndex) {
      // 第一次出现该id，合并count行
      return {
        rowspan: count,
        colspan: 1
      }
    } else {
      // 不是第一次出现该id，不显示
      return {
        rowspan: 0,
        colspan: 0
      }
    }
  }
}
// 是否显示编辑按钮
// 如果关联产品中存在product_id为0或者wid为0的行，则显示编辑按钮
const isShowEdit = computed(() => {
  const isShow =
    dataList.value.some((item) => item.product_id == 0 || item.wid == 0) &&
    props.currentRow.order_status != 70
  return isShow
})

const DialogShopCheckedRef = ref<InstanceType<typeof DialogShopChecked>>()
const exceptionDetailsVisible = ref(false)
const currentExceptionId = ref<number>(0)
const exceptionDetailsList = ref<any[]>([])

// 校对商品
const handleExceptionDetails = () => {
  // 打开异常商品详情弹窗
  exceptionDetailsVisible.value = true
  exceptionDetailsList.value = dataList.value
    .filter((item) => item.product_id == 0 || item.wid == 0)
    .map((item) => ({ ...item })) // 使用展开运算符创建新对象
}

const handleEditOrderItem = (row: Record<string, any>) => {
  // 拿到当前商品的wid、is_futures、product_name
  const wid = dataList.value.find((item) => item.id === row.id)?.wid
  const is_futures = dataList.value.find((item) => item.id === row.id)?.is_futures
  const product_name = props.currentRow.isWholesal
    ? dataList.value.find((item) => item.id === row.id && item.product_id != 0)?.product_name
    : dataList.value.find((item) => item.id === row.id && item.product_id != 0)?.name

  // 编辑异常商品
  const exceptionData = {
    product_name: product_name,
    wid: wid
  }
  currentExceptionId.value = row.id
  DialogShopCheckedRef!.value!.dialogVisible = true
  DialogShopCheckedRef!.value!.initialize([], undefined, exceptionData)
}

const getExposeMultipleData = (val: any[]) => {
  // 获取修改异常商品数据

  exceptionDetailsList.value.forEach((item) => {
    if (item.id === currentExceptionId.value) {
      item.product_id = val[0].product_id
      if (props.currentRow.isWholesal) {
        item.product_name = val[0].product_name
        item.product_code = val[0].product_code
      } else {
        item.name = val[0].product_name
        item.code = val[0].product_code
      }

      item.brand = val[0].brand
      item.wid = val[0].wid
      item.is_futures = val[0].is_futures
      item.arrival_date = val[0].arrival_date
      item.real_arrival_date = val[0].real_arrival_date
      item.hashrate = val[0].hashrate
    }
  })
}

const handleCancelExceptionDetails = () => {
  // 关闭异常商品详情弹窗
  exceptionDetailsVisible.value = false
}

const handleSaveExceptionDetails = () => {
  // 保存异常商品
  exceptionDetailsVisible.value = false

  checkExceptionOrderItem(props.currentRow.id, {
    product_list: exceptionDetailsList.value
  }).then((res) => {
    if (0 == res.code) {
      ElMessage.success(res.message ?? t('common.operateSucMsg'))
      // window.location.reload()
      emit('refresh')
    }
  })
}

const handleNoDelivery = (row: Record<string, any>) => {
  ElMessageBox.confirm(t('common.message.operate'), t('common.tip'), {
    confirmButtonText: t('common.ok'),
    cancelButtonText: t('common.cancel'),
    type: 'warning'
  })
    .then(async () => {
      noDeliveryApi({
        id: props.currentRow.id,
        order_item_id: row.id
      }).then((res) => {
        ElMessage.success(res.message ?? t('common.operateSucMsg'))
        window.location.reload()
      })
    })
    .catch(() => {
      // 取消操作
    })
}
const goWholesal = (row: Record<string, any>) => {
  push({
    path: `/order/wholesal-order-management/detail`,
    query: {
      id: row.wholesal_id
    }
  })
}
</script>

<template>
  <el-dialog
    v-model="exceptionDetailsVisible"
    title="异常商品详情"
    margin-top="1vh"
    width="80vw"
    height="80vh"
  >
    <div>
      <el-table
        :data="exceptionDetailsList"
        stripe
        border
        :cell-style="{ textAlign: 'center' }"
        :header-cell-style="{ textAlign: 'center' }"
      >
        <el-table-column
          :label="t('common.serialNumber')"
          prop="id"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="t('wholesalOrder.warehouse')"
          min-width="160"
          :show-overflow-tooltip="true"
        >
          <template #default="{ row }">
            {{
              useEnumeratePicker(
                currentRow.isWholesal ? operatorOptions.wid : operatorOptions.warehouse,
                row.wid
              )
            }}
          </template>
        </el-table-column>
        <el-table-column
          v-if="currentRow.isWholesal"
          :label="t('wholesalOrder.code')"
          prop="product_code"
          min-width="160"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          v-if="!currentRow.isWholesal"
          :label="t('wholesalOrder.code')"
          prop="code"
          min-width="160"
          :show-overflow-tooltip="true"
        />

        <el-table-column
          v-if="currentRow.isWholesal"
          :label="t('wholesalOrder.name')"
          prop="product_name"
          min-width="200"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          v-if="!currentRow.isWholesal"
          :label="t('wholesalOrder.name')"
          prop="name"
          min-width="200"
          :show-overflow-tooltip="true"
        />

        <el-table-column
          :label="t('wholesalOrder.type')"
          min-width="80"
          :show-overflow-tooltip="true"
        >
          <template #default="{ row }">
            {{ useEnumeratePicker(operatorOptions.is_futures, row.is_futures) }}
          </template>
        </el-table-column>
        <el-table-column
          :label="t('wholesalOrder.arrivalDate')"
          v-show="currentRow.is_futures"
          prop="arrival_date"
          min-width="120"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="t('order.realArrivalDate')"
          v-show="currentRow.is_futures"
          prop="real_arrival_date"
          min-width="120"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="t('order.originalPrice')"
          min-width="120"
          :show-overflow-tooltip="true"
        >
          <template #default="{ row }">
            {{ row.original_price }}({{ row.actual_quoted_currency_name }})
          </template>
        </el-table-column>
        <el-table-column
          :label="t('order.discountedPrice')"
          min-width="120"
          :show-overflow-tooltip="true"
        >
          <template #default="{ row }">
            {{ row.actual_price }}({{ row.actual_quoted_currency_name }})
          </template>
        </el-table-column>
        <el-table-column
          :label="t('order.theActualPricePaid')"
          min-width="120"
          :show-overflow-tooltip="true"
        >
          <template #default="{ row }">
            {{ row.actual_selling_price }}({{
              useEnumeratePicker(operatorOptions.currency, currentRow?.currency ?? '')
            }})
          </template>
        </el-table-column>
        <el-table-column
          v-if="currentRow.isWholesal"
          :label="t('wholesalOrder.quantityPurchased')"
          prop="pay_quantity"
          min-width="100"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          v-if="currentRow.isWholesal"
          :label="t('wholesalOrder.pendingQuantity')"
          prop="quantity_to_be_shipped"
          min-width="100"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          v-if="!currentRow.isWholesal"
          :label="t('order.quantity')"
          prop="quantity"
          min-width="80"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          v-if="!currentRow.isWholesal"
          :label="t('wholesalOrder.pendingQuantity')"
          prop="pending_quantity"
          min-width="80"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="t('order.exceptionstatus')"
          min-width="100"
          :show-overflow-tooltip="true"
        >
          <template #default="{ row }">
            {{ useEnumeratePicker(operatorOptions.exceptionstatus, row.exceptionstatus) }}
          </template>
        </el-table-column>

        <el-table-column
          :label="t('wholesalOrder.brand')"
          min-width="80"
          :show-overflow-tooltip="true"
        >
          <template #default="{ row }">
            {{ useEnumeratePicker(operatorOptions.brand, row.brand) }}
          </template>
        </el-table-column>
        <el-table-column
          :label="t('wholesalOrder.computingPower')"
          prop="hashrate"
          min-width="80"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="t('wholesalOrder.warranty')"
          prop="expiration_date"
          min-width="80"
          :show-overflow-tooltip="true"
        />
        <el-table-column
          :label="t('common.operation')"
          min-width="80"
          :show-overflow-tooltip="true"
          fixed="right"
        >
          <template #default="{ row }">
            <el-button size="small" type="primary" @click="handleEditOrderItem(row)">
              {{ t('common.edit') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="text-14px font-bold my-20px flex justify-end">
        <el-button @click="handleCancelExceptionDetails">
          {{ t('common.cancel') }}
        </el-button>
        <el-button type="primary" @click="handleSaveExceptionDetails">
          {{ t('common.save') }}
        </el-button>
      </div>
    </div>
  </el-dialog>
  <!--  校对商品选择商品弹框-->
  <DialogShopChecked
    ref="DialogShopCheckedRef"
    :type="2"
    :multiple="false"
    @expose-multiple-data="getExposeMultipleData"
    class="mobile-dialog"
  />

  <el-card shadow="always">
    <div @click="togglePanel" class="header">
      <span
        >{{ t('order.relatedProducts') }}&nbsp;&nbsp;
        <span class="text-14px font-400">
          (&nbsp;&nbsp;{{ t('payment.total_amount') }}:{{
            currentRow.total_amount
          }}&nbsp;&nbsp;&nbsp;&nbsp;{{ t('payment.paid_amount') }}:
          {{ currentRow.pay_amount }}&nbsp;&nbsp;)&nbsp;&nbsp;

          <el-button
            v-if="isShowEdit && currentRow.order_status !== 20"
            size="small"
            type="primary"
            @click.stop="handleExceptionDetails"
          >
            {{ t('order.check_product') }}
          </el-button>
        </span>
      </span>

      <el-icon v-if="isExpanded">
        <el-icon-arrow-down />
      </el-icon>
      <el-icon v-else>
        <el-icon-arrow-right />
      </el-icon>
    </div>
    <el-collapse-transition>
      <div v-show="isExpanded" class="w-full">
        <!-- 桌面端表格 -->
        <el-table
          v-if="!isMobile"
          :data="dataList"
          highlight-current-row
          stripe
          border
          :cell-style="{ textAlign: 'center' }"
          :header-cell-style="{ textAlign: 'center' }"
        >
          <!-- <el-table-column
            :label="t('common.serialNumber')"
            prop="id"
            :show-overflow-tooltip="true"
          /> -->
          <el-table-column
            :label="t('wholesalOrder.warehouse')"
            min-width="200"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{
                useEnumeratePicker(
                  currentRow.isWholesal ? operatorOptions.wid : operatorOptions.warehouse,
                  row.wid
                )
              }}
            </template>
          </el-table-column>
          <el-table-column
            v-if="currentRow.isWholesal"
            :label="t('wholesalOrder.code')"
            prop="product_code"
            min-width="200"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            v-if="!currentRow.isWholesal"
            :label="t('wholesalOrder.code')"
            prop="code"
            min-width="200"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            v-if="currentRow.isWholesal"
            :label="t('wholesalOrder.name')"
            prop="product_name"
            min-width="240"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            v-if="!currentRow.isWholesal"
            :label="t('wholesalOrder.name')"
            prop="name"
            min-width="200"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            v-if="!currentRow.isWholesal && currentRow.order_type == 2"
            :label="t('router.order.wholesal.menu')"
            prop="wholesal_no"
            min-width="200"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              <ElLink type="primary" @click="goWholesal(row)" v-if="row.wholesal_id">
                {{ row.wholesal_no }}
              </ElLink>
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.type')"
            min-width="80"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ useEnumeratePicker(operatorOptions.is_futures, row.is_futures) }}
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.arrivalDate')"
            prop="arrival_date"
            min-width="120"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('order.realArrivalDate')"
            prop="real_arrival_date"
            min-width="120"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('order.originalPrice')"
            min-width="120"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ row.original_price }}({{ row.actual_quoted_currency_name }})
            </template>
          </el-table-column>
          <el-table-column
            :label="t('order.discountedPrice')"
            min-width="120"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ row.actual_price }}({{ row.actual_quoted_currency_name }})
            </template>
          </el-table-column>
          <el-table-column
            :label="t('order.theActualPricePaid')"
            min-width="120"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ row.actual_selling_price }}({{
                useEnumeratePicker(operatorOptions.currency, currentRow?.currency ?? '')
              }})
            </template>
          </el-table-column>
          <el-table-column
            v-if="currentRow.isWholesal"
            :label="t('wholesalOrder.quantityPurchased')"
            prop="pay_quantity"
            min-width="150"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            v-if="currentRow.isWholesal"
            :label="t('wholesalOrder.pendingQuantity')"
            prop="quantity_to_be_shipped"
            min-width="150"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            v-if="!currentRow.isWholesal"
            :label="t('order.quantity')"
            prop="quantity"
            min-width="120"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            v-if="!currentRow.isWholesal"
            :label="t('wholesalOrder.pendingQuantity')"
            prop="pending_quantity"
            min-width="120"
            :show-overflow-tooltip="true"
          />

          <el-table-column
            :label="t('order.exceptionstatus')"
            min-width="120"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ useEnumeratePicker(operatorOptions.exceptionstatus, row.exceptionstatus) }}
            </template>
          </el-table-column>

          <el-table-column
            :label="t('wholesalOrder.brand')"
            min-width="200"
            :show-overflow-tooltip="true"
          >
            <template #default="{ row }">
              {{ useEnumeratePicker(operatorOptions.brand, row.brand) }}
            </template>
          </el-table-column>
          <el-table-column
            :label="t('wholesalOrder.computingPower')"
            prop="hashrate"
            min-width="150"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('wholesalOrder.warranty')"
            prop="expiration_date"
            min-width="120"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            :label="t('order.remark')"
            prop="remark"
            min-width="280"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            fixed="right"
            :label="t('common.operation')"
            v-if="
              currentRow.order_category == 'order' &&
              currentRow.review_node != 1 &&
              (currentRow.pay_status == 3 || currentRow.pay_status == 4)
            "
            width="100"
          >
            <template #default="{ row }">
              <el-button
                v-hasPermi="['OrderManagementNoDelivery']"
                v-if="
                  row.pending_quantity > 0 &&
                  currentRow.review_node != 1 &&
                  [3, 4].includes(currentRow.pay_status) &&
                  currentRow.order_status != 70 &&
                  currentRow.order_type != 2
                "
                type="primary"
                @click="handleNoDelivery(row)"
                size="small"
              >
                {{ t('order.noDelivery') }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>

        <!-- 移动端卡片布局 -->
        <div v-else class="mobile-card-container">
          <div v-for="(row, index) in dataList" :key="index" class="mobile-card pt-15px">
            <div class="card-header">
              <div class="card-title"> 产品信息 </div>
            </div>

            <div class="card-content">
              <div class="info-grid">
                <div class="info-item">
                  <span class="label">{{ t('wholesalOrder.warehouse') }}</span>
                  <span class="value">
                    {{
                      useEnumeratePicker(
                        currentRow.isWholesal ? operatorOptions.wid : operatorOptions.warehouse,
                        row.wid
                      )
                    }}
                  </span>
                </div>

                <div class="info-item">
                  <span class="label">{{ t('wholesalOrder.code') }}</span>
                  <span class="value">{{
                    currentRow.isWholesal ? row.product_code : row.code
                  }}</span>
                </div>

                <div class="info-item">
                  <span class="label">{{ t('wholesalOrder.name') }}</span>
                  <span class="value">{{
                    currentRow.isWholesal ? row.product_name : row.name
                  }}</span>
                </div>

                <div class="info-item">
                  <span class="label">{{ t('wholesalOrder.type') }}</span>
                  <span class="value">
                    {{ useEnumeratePicker(operatorOptions.is_futures, row.is_futures) }}
                  </span>
                </div>

                <div class="info-item" v-show="row.is_futures">
                  <span class="label">{{ t('wholesalOrder.arrivalDate') }}</span>
                  <span class="value">{{ row.arrival_date }}</span>
                </div>

                <div class="info-item" v-show="row.is_futures">
                  <span class="label">{{ t('order.realArrivalDate') }}</span>
                  <span class="value">{{ row.real_arrival_date }}</span>
                </div>

                <div class="info-item">
                  <span class="label">{{ t('order.originalPrice') }}</span>
                  <span class="value"
                    >{{ row.original_price }}({{ row.actual_quoted_currency_name }})</span
                  >
                </div>

                <div class="info-item">
                  <span class="label">{{ t('order.discountedPrice') }}</span>
                  <span class="value"
                    >{{ row.actual_price }}({{ row.actual_quoted_currency_name }})</span
                  >
                </div>

                <div class="info-item">
                  <span class="label">{{ t('order.theActualPricePaid') }}</span>
                  <span class="value">
                    {{ row.actual_selling_price }}({{
                      useEnumeratePicker(operatorOptions.currency, currentRow?.currency ?? '')
                    }})
                  </span>
                </div>

                <div v-if="currentRow.isWholesal" class="info-item">
                  <span class="label">{{ t('wholesalOrder.quantityPurchased') }}</span>
                  <span class="value">{{ row.pay_quantity }}</span>
                </div>

                <div v-if="currentRow.isWholesal" class="info-item">
                  <span class="label">{{ t('wholesalOrder.pendingQuantity') }}</span>
                  <span class="value">{{ row.quantity_to_be_shipped }}</span>
                </div>

                <div v-if="!currentRow.isWholesal" class="info-item">
                  <span class="label">{{ t('order.quantity') }}</span>
                  <span class="value">{{ row.quantity }}</span>
                </div>

                <div class="info-item">
                  <span class="label">{{ t('wholesalOrder.brand') }}</span>
                  <span class="value">
                    {{ useEnumeratePicker(operatorOptions.brand, row.brand) }}
                  </span>
                </div>

                <div class="info-item">
                  <span class="label">{{ t('wholesalOrder.computingPower') }}</span>
                  <span class="value">{{ row.hashrate }}</span>
                </div>

                <div class="info-item">
                  <span class="label">{{ t('wholesalOrder.warranty') }}</span>
                  <span class="value">{{ row.expiration_date }}</span>
                </div>
                <div class="info-item">
                  <span class="label">{{ t('order.remark') }}</span>
                  <span class="value">{{ row.remark }}</span>
                </div>
                <div class="info-item flex">
                  <el-button
                    v-hasPermi="['OrderManagementNoDelivery']"
                    v-if="
                      row.pending_quantity > 0 &&
                      currentRow.review_node != 1 &&
                      [3, 4].includes(currentRow.pay_status) &&
                      currentRow.order_status != 70 &&
                      currentRow.order_type != 2
                    "
                    plain
                    @click="handleNoDelivery(row)"
                    size="small"
                  >
                    {{ t('order.noDelivery') }}
                  </el-button>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- ==========================================================部分发货产品-================================================================= -->
        <div
          class="text-14px font-bold my-20px"
          v-if="
            !currentRow.isWholesal &&
            !isMobile &&
            currentRow.pay_status === 4 &&
            partDeliveryList.length > 0
          "
          >{{ t('order.partDeliveryProducts') }}</div
        >
        <template v-if="!currentRow.isWholesal && currentRow.pay_status === 4">
          <el-table
            v-if="!isMobile && partDeliveryList.length > 0"
            :data="partDeliveryList"
            highlight-current-row
            stripe
            border
            :cell-style="{ textAlign: 'center' }"
            :header-cell-style="{ textAlign: 'center' }"
            :span-method="mergeCells"
          >
            <el-table-column
              :label="t('wholesalOrder.warehouse')"
              min-width="200"
              :show-overflow-tooltip="true"
            >
              <template #default="{ row }">
                {{
                  useEnumeratePicker(
                    currentRow.isWholesal ? operatorOptions.wid : operatorOptions.warehouse,
                    row.warehouse_id
                  )
                }}
              </template>
            </el-table-column>
            <el-table-column
              v-if="currentRow.isWholesal"
              :label="t('wholesalOrder.code')"
              prop="product_code"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              v-if="!currentRow.isWholesal"
              :label="t('wholesalOrder.code')"
              prop="code"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              v-if="currentRow.isWholesal"
              :label="t('wholesalOrder.name')"
              prop="product_name"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              v-if="!currentRow.isWholesal"
              :label="t('wholesalOrder.name')"
              prop="name"
              min-width="200"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('wholesalOrder.type')"
              min-width="120"
              :show-overflow-tooltip="true"
            >
              <template #default="{ row }">
                {{ useEnumeratePicker(operatorOptions.is_futures, row.is_futures) }}
              </template>
            </el-table-column>
            <el-table-column
              :label="t('order.theQuantityToBeShipped')"
              prop="pending_quantity"
              min-width="120"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.applyDeliveryQuantity')"
              prop="apply_quantity"
              min-width="120"
              :show-overflow-tooltip="true"
            />

            <el-table-column
              :label="t('order.originalPrice')"
              min-width="160"
              :show-overflow-tooltip="true"
            >
              <template #default="{ row }">
                <span v-if="row.actual_quoted_currency_name"
                  >{{ row.original_price }}({{ row.actual_quoted_currency_name }})</span
                >
              </template>
            </el-table-column>
            <el-table-column
              :label="t('order.discountedPrice')"
              min-width="160"
              :show-overflow-tooltip="true"
            >
              <template #default="{ row }">
                <span v-if="row.actual_quoted_currency_name"
                  >{{ row.actual_price }}({{ row.actual_quoted_currency_name }})</span
                >
              </template>
            </el-table-column>
            <el-table-column
              :label="t('order.theActualPricePaid')"
              min-width="160"
              :show-overflow-tooltip="true"
            >
              <template #default="{ row }">
                <span v-if="row.actual_selling_price"
                  >{{ row.actual_selling_price }}({{
                    useEnumeratePicker(operatorOptions.currency, currentRow?.currency ?? '')
                  }})</span
                >
              </template>
            </el-table-column>

            <el-table-column
              :label="t('wholesalOrder.brand')"
              min-width="120"
              :show-overflow-tooltip="true"
            >
              <template #default="{ row }">
                {{ useEnumeratePicker(operatorOptions.brand, row.brand) }}
              </template>
            </el-table-column>
            <el-table-column
              :label="t('wholesalOrder.computingPower')"
              prop="hashrate"
              min-width="150"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('wholesalOrder.warranty')"
              prop="expiration_date"
              min-width="120"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('invoice.applicant')"
              prop="creator_name"
              min-width="120"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              :label="t('order.applyTime')"
              prop="create_time"
              min-width="120"
              :show-overflow-tooltip="true"
            />

            <el-table-column fixed="right" :label="t('common.operation')" width="100">
              <template #default="{ row }" v-if="currentRow.order_status !== 20">
                <el-button
                  v-hasPermi="['OrderManagementPartDeliveryReview']"
                  v-if="row.status == 1"
                  type="primary"
                  @click="handleAudit(row)"
                  size="small"
                >
                  {{ t('wholesalOrder.audit') }}
                </el-button>
                <el-button
                  v-hasPermi="['OrderManagementDelivery']"
                  v-if="row.status == 2 && row.pending_quantity && row.fl_warehouse_id"
                  type="primary"
                  @click="handleJump(row)"
                  size="small"
                >
                  {{ t('order.delivery') }}
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </div>
    </el-collapse-transition>
  </el-card>
</template>

<style scoped>
.header {
  display: flex;
  height: 40px;
  padding: 0 10px;
  margin-bottom: 10px;
  font-weight: 900;
  cursor: pointer;
  background-color: #f3f3f3;
  border-radius: 5px;
  align-items: center;
  justify-content: space-between;
}
</style>
